package com.example.footballsystem.service;

import com.example.footballsystem.entity.PlayerCard;
import com.example.footballsystem.mapper.PlayerCardMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Slf4j
@Service
public class PlayerCardService {
    @Autowired
    PlayerCardMapper playerCardMapper;

    //获取全部预定信息
    public List<PlayerCard> getAllPlayerCard(){
        return playerCardMapper.getAllPlayerCard();
    }
    public List<PlayerCard> getPlayerCard(String info){
        List<PlayerCard> resultList = new ArrayList<>();
        int count = 0;

        if(!playerCardMapper.getPlayerCardByName(info).isEmpty()){
            resultList.addAll((playerCardMapper.getPlayerCardByName(info)));
            count++;
        }
        if(!playerCardMapper.getPlayerCardByAccount(info).isEmpty()){
            resultList.addAll((playerCardMapper.getPlayerCardByAccount(info)));
            count++;
        }
        for (int i=0;i<count;i++) {
            for (int j=i+1;j<count;j++) {
                if(Objects.equals(resultList.get(j).getPlayerAccount(), resultList.get(j).getPlayerAccount())){
                    log.info(i+" "+j);
                    resultList.remove(j);
                    j--;
                    count--;
                }
            }
        }
        //log.info(resultList.toString());
        return resultList;
    }
    public Boolean addPlayerCard(PlayerCard playerCard){
        Timestamp timestamp = new Timestamp(System.currentTimeMillis());
        playerCard.setCteateDate(timestamp.toString());
        return playerCardMapper.addPlayerCard(playerCard);
    }
    public Boolean deletePlayerCard(String playerCardAccount){
        return playerCardMapper.deletePlayerCard(playerCardAccount);
    }
}
